<?php /* Smarty version Smarty-3.0.6, created on 2011-10-15 00:16:23
         compiled from "templates/s027_1.dwt" */ ?>
<?php /*%%SmartyHeaderCode:172774e98d0d7651795-78417350%%*/if(!defined('SMARTY_DIR')) exit('no direct access allowed');
$_smarty_tpl->decodeProperties(array (
  'file_dependency' => 
  array (
    '930938a424fd7c431358e3e860c2500783a4ee5d' => 
    array (
      0 => 'templates/s027_1.dwt',
      1 => 1318581733,
      2 => 'file',
    ),
  ),
  'nocache_hash' => '172774e98d0d7651795-78417350',
  'function' => 
  array (
  ),
  'has_nocache_code' => false,
)); /*/%%SmartyHeaderCode%%*/?>
<?php if (!is_callable('smarty_function_html_options')) include 'D:\study\smarty\plugins\function.html_options.php';
if (!is_callable('smarty_modifier_date_format')) include 'D:\study\smarty\plugins\modifier.date_format.php';
if (!is_callable('smarty_function_html_select_date')) include 'D:\study\smarty\plugins\function.html_select_date.php';
if (!is_callable('smarty_function_html_select_time')) include 'D:\study\smarty\plugins\function.html_select_time.php';
if (!is_callable('smarty_function_popup_init')) include 'D:\study\smarty\plugins\function.popup_init.php';
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title><?php echo $_smarty_tpl->getVariable('title')->value;?>
</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
</head>

<body>
<?php $_template = new Smarty_Internal_Template("top.tpl", $_smarty_tpl->smarty, $_smarty_tpl, $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, null, null);
$_template->assign('title','title'); echo $_template->getRenderedTemplate();?><?php $_template->updateParentVariables(0);?><?php unset($_template);?>

<div class="text">
<b>smarty的简单配置</b>
<strong>smarty</strong>模板引擎是一个历史悠久简洁高效的模板引擎。<br />
<strong>smarty</strong>模板引擎把php分为php源文件和模板文件，运行时编译成一个完整的混编文件执行。使得程序和美工彻底分离。<br />
<strong>smarty</strong>还有缓存功能，能大大降低服务器的运算压力。<br />
下面我们来配置<strong>smarty</strong>模板引擎<br />
首先建立一个php文件，在里面写入smarty的一些配置：
<div class="code">
&lt;?php<br />
  require('smarty/Smarty.class.php');	//引入smarty.class.php的类库文件。这个文件里包含了smarty所有的类。<br />
  $smarty = new Smarty;					//把smarty实例化<br />
  //$smarty-&gt;force_compile = true;	//<br />
  $smarty-&gt;debugging = false;		//这个配置是smarty的调试模式，true为开启，false为关闭。<br />
  $smarty-&gt;caching = false;		//这个配置是smarty是否调用缓存，一般我们调试时候不开启缓存，到服务器上需要开启缓存。<br />
  // $smarty-&gt;cache_lifetime = 120;	//这个配置为缓存存在时间。也就是过120秒后缓存消失。<br />
  ?&gt;
</div>
</div>

<div class="text">
<b>assign方法</b>
<strong>assign</strong>是将php文件的值赋到模板文件的变量中的一个方法。使用方式为<br />
<strong>assign</strong>("模板变量","php文件的值");
下面有3个实例。
<div class="code">
$smarty-&gt;assign(&quot;title&quot;,&quot;php学习笔记027&quot;);<br />
$smarty-&gt;assign(&quot;tip&quot;,&quot;027 smarty模板引擎的使用&quot;);<br />
$smarty-&gt;assign(&quot;name&quot;,&quot;Fred Irving Johnathan Bradley Peppergill&quot;,true);<br />
</div>
我们在模板文件中写入这样的句子。<br />
<div class="code">
{$title}//输出assign的title变量<br />
{$tip}//输出assign的tip变量<br />
{$name|upper}//用大写的方式输出name的值<br />
</div>
我们来看实现的效果。
<div class="effect">
<?php echo $_smarty_tpl->getVariable('title')->value;?>
<br />
<?php echo $_smarty_tpl->getVariable('tip')->value;?>
<br />
<?php echo ((mb_detect_encoding($_smarty_tpl->getVariable('name')->value, 'UTF-8, ISO-8859-1') === 'UTF-8') ? mb_strtoupper($_smarty_tpl->getVariable('name')->value,SMARTY_RESOURCE_CHAR_SET) : strtoupper($_smarty_tpl->getVariable('name')->value));?>
<br />
</div>
显然，这样的功能远远不能满足我们的使用需求，那么我们来看看assign处理数组的能力。<br />
<b>section循环</b>
<strong>section</strong>是smarty模板里面的循环命令，我们用下面这个例子说明它如何循环输出数组。<br />
我们在php文件里面加入这样的代码
<div class="code">
  &lt;?php<br />
  $smarty-&gt;assign(&quot;Firstname&quot;,array(&quot;John&quot;,&quot;Mary&quot;,&quot;James&quot;,&quot;Henry&quot;));<br />
  $smarty-&gt;assign(&quot;Lastname&quot;,array(&quot;Doe&quot;,&quot;Smith&quot;,&quot;Johnson&quot;,&quot;Case&quot;,&quot;55555&quot;));<br />  
  ?&gt;
</div>
我们在模板文件加入以下的代码<br />
<div class="code">
{section name=outer loop=$Firstname}	//section函数开始，定义循环名称（自定义），循环的变量，需要在php文件中赋值。<br />
{if $smarty.section.outer.index is odd by 1}	//这是一个定义循环行奇偶性的函数，1为每行一组定义奇数/偶数，2为每两行一组，依次类推。<br />
{$smarty.section.outer.rownum} . {$Firstname[outer]} {$Lastname[outer]}&lt;br /&gt;<br />
<b>//$smarty.section.outer.rownum(这是行号函数)<br />
//$Firstname[outer]（循环变量和循环名）<br />
//$Lastname[outer]（第二个循环变量和循环名称）这个有5个值但是我们定义的是前一个循环变量，所以在第四个的时候就结束了。</b>
{else}<br />
{$smarty.section.outer.rownum} * {$Firstname[outer]} {$Lastname[outer]}&lt;br /&gt;<br />
{/if}<br />
{sectionelse}<br />
none<br />
{/section}
</div>  
我们来观察其运行结果。
<div class="effect">
<?php unset($_smarty_tpl->tpl_vars['smarty']->value['section']['outer']);
$_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['name'] = 'outer';
$_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['loop'] = is_array($_loop=$_smarty_tpl->getVariable('Firstname')->value) ? count($_loop) : max(0, (int)$_loop); unset($_loop);
$_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['show'] = true;
$_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['max'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['loop'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['step'] = 1;
$_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['start'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['step'] > 0 ? 0 : $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['loop']-1;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['show']) {
    $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['total'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['loop'];
    if ($_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['total'] == 0)
        $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['show'] = false;
} else
    $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['total'] = 0;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['show']):

            for ($_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['index'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['start'], $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['iteration'] = 1;
                 $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['iteration'] <= $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['total'];
                 $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['index'] += $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['step'], $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['iteration']++):
$_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['rownum'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['iteration'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['index_prev'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['index'] - $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['index_next'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['index'] + $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['first']      = ($_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['iteration'] == 1);
$_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['last']       = ($_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['iteration'] == $_smarty_tpl->tpl_vars['smarty']->value['section']['outer']['total']);
?>
<?php if ((1 & $_smarty_tpl->getVariable('smarty')->value['section']['outer']['index'] / 1)){?>
<?php echo $_smarty_tpl->getVariable('smarty')->value['section']['outer']['rownum'];?>
 . <?php echo $_smarty_tpl->getVariable('Firstname')->value[$_smarty_tpl->getVariable('smarty')->value['section']['outer']['index']];?>
 <?php echo $_smarty_tpl->getVariable('Lastname')->value[$_smarty_tpl->getVariable('smarty')->value['section']['outer']['index']];?>
<br />
<?php }else{ ?>
<?php echo $_smarty_tpl->getVariable('smarty')->value['section']['outer']['rownum'];?>
 * <?php echo $_smarty_tpl->getVariable('Firstname')->value[$_smarty_tpl->getVariable('smarty')->value['section']['outer']['index']];?>
 <?php echo $_smarty_tpl->getVariable('Lastname')->value[$_smarty_tpl->getVariable('smarty')->value['section']['outer']['index']];?>
<br />
<?php }?>
<?php endfor; else: ?>
none
<?php endif; ?>
</div>
上述例子我们了解了assign对一维数组的处理，我们来看看其循环对二维数组的处理。<br />
我们在php文件中加入下列代码<br />
<div class="code">
$smarty-&gt;assign(&quot;Class&quot;,array(array(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;,&quot;D&quot;), array(&quot;E&quot;, &quot;F&quot;, &quot;G&quot;, &quot;H&quot;), array(										&quot;I&quot;, &quot;J&quot;, &quot;K&quot;, &quot;L&quot;), array(&quot;M&quot;, &quot;N&quot;, &quot;O&quot;, &quot;P&quot;)));<br />
$smarty-&gt;assign(&quot;contacts&quot;, array(array(&quot;phone&quot; =&gt; &quot;1&quot;, &quot;fax&quot; =&gt; &quot;2&quot;, &quot;cell&quot; =&gt; &quot;3&quot;),array(&quot;phone&quot; =&gt; &quot;555-4444&quot;, &quot;fax&quot; =&gt; &quot;555-3333&quot;, &quot;cell&quot; =&gt; &quot;760-1234&quot;)));<br />
</div>
我们在模板文件中加入下面的代码<br />
<div class="code">
{section name=zm1 loop=$Class}<br />
{section name=zm2 loop=$Class[zm1]}<br />
{$Class[zm1][zm2]}&lt;br /&gt;<br />
{/section}<br />
{/section}<br />
{section name=sec1 loop=$contacts}<br />
phone: {$contacts[sec1].phone}	//这是二维数组的关键帧&lt;br&gt;<br />
fax: {$contacts[sec1].fax}&lt;br&gt;<br />
cell: {$contacts[sec1].cell}&lt;br&gt;<br />
{/section}</div>
我们来看运行的效果
<div class="effect">


<?php unset($_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']);
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['name'] = 'zm1';
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['loop'] = is_array($_loop=$_smarty_tpl->getVariable('Class')->value) ? count($_loop) : max(0, (int)$_loop); unset($_loop);
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['show'] = true;
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['max'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['loop'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['step'] = 1;
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['start'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['step'] > 0 ? 0 : $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['loop']-1;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['show']) {
    $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['total'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['loop'];
    if ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['total'] == 0)
        $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['show'] = false;
} else
    $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['total'] = 0;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['show']):

            for ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['index'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['start'], $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['iteration'] = 1;
                 $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['iteration'] <= $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['total'];
                 $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['index'] += $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['step'], $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['iteration']++):
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['rownum'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['iteration'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['index_prev'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['index'] - $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['index_next'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['index'] + $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['first']      = ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['iteration'] == 1);
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['last']       = ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['iteration'] == $_smarty_tpl->tpl_vars['smarty']->value['section']['zm1']['total']);
?>
<?php unset($_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']);
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['name'] = 'zm2';
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['loop'] = is_array($_loop=$_smarty_tpl->getVariable('Class')->value[$_smarty_tpl->getVariable('smarty')->value['section']['zm1']['index']]) ? count($_loop) : max(0, (int)$_loop); unset($_loop);
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['show'] = true;
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['max'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['loop'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['step'] = 1;
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['start'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['step'] > 0 ? 0 : $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['loop']-1;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['show']) {
    $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['total'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['loop'];
    if ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['total'] == 0)
        $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['show'] = false;
} else
    $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['total'] = 0;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['show']):

            for ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['index'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['start'], $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['iteration'] = 1;
                 $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['iteration'] <= $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['total'];
                 $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['index'] += $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['step'], $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['iteration']++):
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['rownum'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['iteration'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['index_prev'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['index'] - $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['index_next'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['index'] + $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['first']      = ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['iteration'] == 1);
$_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['last']       = ($_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['iteration'] == $_smarty_tpl->tpl_vars['smarty']->value['section']['zm2']['total']);
?>
<?php echo $_smarty_tpl->getVariable('Class')->value[$_smarty_tpl->getVariable('smarty')->value['section']['zm1']['index']][$_smarty_tpl->getVariable('smarty')->value['section']['zm2']['index']];?>
<br />
<?php endfor; endif; ?>
<?php endfor; endif; ?>
<?php unset($_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']);
$_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['name'] = 'sec1';
$_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['loop'] = is_array($_loop=$_smarty_tpl->getVariable('contacts')->value) ? count($_loop) : max(0, (int)$_loop); unset($_loop);
$_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['show'] = true;
$_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['max'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['loop'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['step'] = 1;
$_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['start'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['step'] > 0 ? 0 : $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['loop']-1;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['show']) {
    $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['total'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['loop'];
    if ($_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['total'] == 0)
        $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['show'] = false;
} else
    $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['total'] = 0;
if ($_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['show']):

            for ($_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['index'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['start'], $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['iteration'] = 1;
                 $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['iteration'] <= $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['total'];
                 $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['index'] += $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['step'], $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['iteration']++):
$_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['rownum'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['iteration'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['index_prev'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['index'] - $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['index_next'] = $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['index'] + $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['step'];
$_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['first']      = ($_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['iteration'] == 1);
$_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['last']       = ($_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['iteration'] == $_smarty_tpl->tpl_vars['smarty']->value['section']['sec1']['total']);
?>
phone: <?php echo $_smarty_tpl->getVariable('contacts')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec1']['index']]['phone'];?>
<br>
fax: <?php echo $_smarty_tpl->getVariable('contacts')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec1']['index']]['fax'];?>
<br>
cell: <?php echo $_smarty_tpl->getVariable('contacts')->value[$_smarty_tpl->getVariable('smarty')->value['section']['sec1']['index']]['cell'];?>
<br>
<?php endfor; endif; ?>
</div>

smarty对表单的处理也更加方便。我们在php文件中加入下面的代码<br />
<div class="code">
$smarty-&gt;assign(&quot;option_values&quot;, array(&quot;NY&quot;,&quot;NE&quot;,&quot;KS&quot;,&quot;IA&quot;,&quot;OK&quot;,&quot;TX&quot;));<br />
$smarty-&gt;assign(&quot;option_output&quot;, array(&quot;New York&quot;,&quot;Nebraska&quot;,&quot;Kansas&quot;,&quot;Iowa&quot;,&quot;Oklahoma&quot;,&quot;Texas&quot;));<br />
$smarty-&gt;assign(&quot;option_selected&quot;, &quot;NE&quot;);<br />
 </div>
在模板文件中加入下面的代码<br />
<div class="code">&lt;form&gt;<br />
  &lt;select name=states&gt;<br />
  {html_options values=$option_values selected=$option_selected output=$option_output}<br />
  &lt;/select&gt;<br />
  &lt;/form&gt;
 </div>
我们来看运行的效果<br />
<div class="effect">
<form>
<select name=states>
<?php echo smarty_function_html_options(array('values'=>$_smarty_tpl->getVariable('option_values')->value,'selected'=>$_smarty_tpl->getVariable('option_selected')->value,'output'=>$_smarty_tpl->getVariable('option_output')->value),$_smarty_tpl);?>

</select>
</form><br />
下面是页面解析的源代码:<br />

&lt;form&gt;<br />
&lt;select name=&quot;states&quot;&gt;<br />
&lt;option value=&quot;NY&quot;&gt;New York&lt;/option&gt;<br />
&lt;option value=&quot;NE&quot; selected=&quot;selected&quot;&gt;Nebraska&lt;/option&gt;<br />
&lt;option value=&quot;KS&quot;&gt;Kansas&lt;/option&gt;<br />
&lt;option value=&quot;IA&quot;&gt;Iowa&lt;/option&gt;<br />
&lt;option value=&quot;OK&quot;&gt;Oklahoma&lt;/option&gt;<br />
&lt;option value=&quot;TX&quot;&gt;Texas&lt;/option&gt;<br />
&lt;/select&gt;<br />
&lt;/form&gt;
</div>

<strong>smarty</strong>还有很多自带的参数我们列举几个作为参考。<br />
<div class="code">
当前的日期和时间: {$smarty.now|date_format:&quot;%Y-%m-%d %H:%M:%S&quot;}&lt;br /&gt;<br />
当前页面：{$SCRIPT_NAME}&lt;br /&gt;<br />
当前服务器名称：{$smarty.server.SERVER_NAME}&lt;br /&gt;<br />
一个选择日期的方法：{html_select_date start_year=1998 end_year=2020}&lt;br /&gt;<br />
一个选择时间的方法：{html_select_time use_24_hours=true}<br />
包含一个文件的方法：{include file=&quot;footer.tpl&quot;}&lt;br /&gt;<br />
引用一个js文件的方法：{popup_init src=&quot;/javascripts/overlib.js&quot;}&lt;br /&gt;<br />
</div>
我们来看运行的效果：
<div class="effect">
当前的日期和时间: <?php echo smarty_modifier_date_format(time(),"%Y-%m-%d %H:%M:%S");?>
<br />
当前页面：<?php echo $_smarty_tpl->getVariable('SCRIPT_NAME')->value;?>
<br />
当前服务器名称：<?php echo $_SERVER['SERVER_NAME'];?>
<br />
一个选择日期的方法：<?php echo smarty_function_html_select_date(array('start_year'=>1998,'end_year'=>2020),$_smarty_tpl);?>
<br />
一个选择时间的方法：<?php echo smarty_function_html_select_time(array('use_24_hours'=>true),$_smarty_tpl);?>

包含一个文件的方法：<?php $_template = new Smarty_Internal_Template("footer.tpl", $_smarty_tpl->smarty, $_smarty_tpl, $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, null, null);
 echo $_template->getRenderedTemplate();?><?php $_template->updateParentVariables(0);?><?php unset($_template);?><br />
引用一个js文件的方法：<?php echo smarty_function_popup_init(array('src'=>"/javascripts/overlib.js"),$_smarty_tpl);?>
<br />
</div>

</div>
<div class="text">
<b>display方法</b>
<strong>$smarty->display('templates/s027_1.dwt');</strong>是将php文件与哪个模板文件链接起来的方法。一般写在最底部！
</div>
</body>
</html>
